/** FASSIT (Forms of Selective Attention in Intelligent Transportation Systems)
 * Computational Creativity and Digital Media
 * Cognitive and Media Systems Group
 * Centre for Informatics and Systems of the University of Coimbra (CISUC)
 *
 * Copyright (c) 2010-2013 University of Coimbra, Portugal
 * All rights reserved.
 */
package poi.Info;

import java.io.Serializable;

/**
 * This class is used to get information about the POI's schedule, when the POI
 * is open
 * 
 * @author Hernani Costa
 * @version 0.1 date: 4/11/2012
 */
public class Schedule implements Serializable {
	private static final long serialVersionUID = 1L;
	private boolean morning = false;
	private boolean afternoon = false;
	private boolean night = false;
	private boolean hasSchedule = false;

	/**
	 * ------------------------------------------------------------------------
	 * Constructor class
	 * ------------------------------------------------------------------------
	 * 
	 * @param morning
	 * @param afternoon
	 * @param night
	 */
	public Schedule(boolean morning, boolean afternoon, boolean night) {
		this.setOpenMorning(morning);
		this.setOpenAfternoon(afternoon);
		this.setOpenNight(night);
	}

	/**
	 * ------------------------------------------------------------------------
	 * Constructor class
	 * ------------------------------------------------------------------------
	 * 
	 * @param schedule
	 *            - string containing the schedule for the daysOpen
	 */
	public Schedule(String schedule) {
		// System.out.println("\n Schedule::" + schedule);
		if (!schedule.equals("")) {
			this.setHasSchedule(true);
			String[] temp = schedule.split(",");
			for (String t : temp) {
				t = t.trim();
				if (t.contains("Morning")) {
					this.setOpenMorning(true);
				} else if (t.contains("Afternoon")) {
					this.setOpenAfternoon(true);

				} else if (t.contains("Night")) {
					this.setOpenNight(true);

				}
			}
		} else {
			this.setHasSchedule(false);
		}
	}

	// ------------------------------------------------------------------------
	// ------------------------GETs and SETs-----------------------------------
	// ------------------------------------------------------------------------

	public int[] getSchedule() {

		int[] schedule = new int[3];
		if (this.isOpenMorning()) {
			schedule[0] = 1;

		}
		if (this.isOpenAfternoon()) {
			schedule[1] = 1;

		}
		if (this.isOpenNight()) {
			schedule[2] = 1;

		}
		return schedule;
	}

	public boolean hasSchedule() {
		return hasSchedule;
	}

	private void setHasSchedule(boolean hasSchedule) {
		this.hasSchedule = hasSchedule;
	}

	public boolean isOpenAfternoon() {
		return afternoon;
	}

	private void setOpenAfternoon(boolean afternoon) {
		this.afternoon = afternoon;
	}

	public boolean isOpenMorning() {
		return morning;
	}

	private void setOpenMorning(boolean morning) {
		this.morning = morning;
	}

	public boolean isOpenNight() {
		return night;
	}

	private void setOpenNight(boolean night) {
		this.night = night;
	}

	/**
	 * 
	 * @return the number of parts of the day where the POI is open
	 */
	public int getCount() {
		int count = 0;
		if (isOpenMorning())
			count += 1;
		if (isOpenAfternoon())
			count += 1;

		if (isOpenNight())
			count += 1;

		return count;
	}

	public String getScheduleInaString() {
		String i = "";
		if (isOpenMorning())
			i += "Morning ";
		if (isOpenAfternoon())
			i += " Afternoon";
		if (isOpenNight())
			i += " Night";
		return i;
	}

	public boolean isOpenInThisPeriodOfDay(String periodOfDay) {
		if (isOpenMorning() && (periodOfDay.equalsIgnoreCase("Morning")))
			return true;
		if (isOpenAfternoon() && (periodOfDay.equalsIgnoreCase("Afternoon")))
			return true;
		if (isOpenNight() && (periodOfDay.equalsIgnoreCase("Night")))
			return true;
		return false;
	}

	/**
	 * ------------------------------------------------------------------------
	 * Returns a String with all the Schedule information
	 * ------------------------------------------------------------------------
	 */
	public String to_String() {
		int[] i = new int[3];
		if (isOpenMorning())
			i[0] = 1;
		else
			i[0] = 0;
		if (isOpenAfternoon())
			i[1] = 1;
		else
			i[1] = 0;
		if (isOpenNight())
			i[2] = 1;
		else
			i[2] = 0;

		String info = "(" + i[0] + "," + i[1] + "," + i[2] + ")";

		// String info = String.format(
		// "[morning=%b, afthernoon=%b, night=%b]",
		// isOpenMorning(), isOpenAfternoon(), isOpenNight());
		return info;
	}

	/**
	 * ------------------------------------------------------------------------
	 * Used to provide an example that exercises the functionality of the class.
	 * ------------------------------------------------------------------------
	 * 
	 * @param args
	 */
	public static void main(String args[]) {
		Schedule s = new Schedule("Morning,Night");
		System.out.println(s.getScheduleInaString());

	}
}
